/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.room.phom;

import extension.phom.handler.PhomFlag;
import extension.phom.handler.PhomCommand;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import extension.game.room.GameResponse;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author daz
 */
public class PhomResponse extends GameResponse {

    public PhomResponse(PhomExtension ext) {
        super(ext);
    }

    void sendDealCard(List<Integer> listCards, List<Integer> listPhom, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(PhomFlag.LIST_CARD, listCards);
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        ext.send(PhomCommand.DEAL_CARD, resObj, user);
        log(resObj);
    }

    void sendFirstTurn(int gameTurn, List<User> userList) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.FIRST_TURN, gameTurn);
        resObj.putInt(PhomFlag.CAN_DRAW_CARD, 0);
        ext.send(PhomCommand.FIRST_TURN, resObj, userList);
        log(resObj);
    }

    public void sendFirstTurn(int gameTurn, User userList) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.FIRST_TURN, gameTurn);
        resObj.putInt(PhomFlag.CAN_DRAW_CARD, 0);
        ext.send(PhomCommand.FIRST_TURN, resObj, userList);
        log(resObj);
    }

    public void sendFightCard(int canFight, int playerFight, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.PLAYER_FIGHT, playerFight);
        resObj.putInt(PhomFlag.CAN_FIGHT, canFight);
        ext.send(PhomCommand.FIGHT_CARD, resObj, user);
        log(resObj);
    }

    public void sendFightCard(int cardSend, int canFight, int gameTurn, List<User> listSend) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.CARD_SEND, cardSend);
        resObj.putInt(PhomFlag.PLAYER_FIGHT, gameTurn);
        resObj.putInt(PhomFlag.CAN_FIGHT, canFight);
        ext.send(PhomCommand.FIGHT_CARD, resObj, listSend);
        log(resObj);
    }

    public void sendFightCard(int cardSend, int automatic, int canFight, int gameTurn, List<Integer> listPhom, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.CARD_SEND, cardSend);
        resObj.putInt(PhomFlag.PLAYER_FIGHT, gameTurn);
        resObj.putInt(PhomFlag.CAN_FIGHT, canFight);
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        resObj.putInt(PhomFlag.AUTOMATIC, automatic);
        ext.send(PhomCommand.FIGHT_CARD, resObj, user);
        log(resObj);
    }

    public void sendDrawCard(int drawCard, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.DRAW_CARD, drawCard);
        resObj.putInt("show_type", 0);
//        if (!listPhom.isEmpty()) {
//            resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
//        }
        ext.send(PhomCommand.DRAW_CARD, resObj, user);
        log(resObj);
    }

    public void sendDrawCard(int drawCard, List<Integer> listPhom, int havePhom, int playerFinish, int showPhomType, User user) {
        delay();
        //showPhomType :0 ko gui gi ca, 1 ha phom , 2 tai phom
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.DRAW_CARD, drawCard);
        
//        if (!listPhom.isEmpty()) {
//            resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
//        }
        
        if (showPhomType != 0) {
            resObj.putInt(PhomFlag.HAVE_PHOM, havePhom);
            resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
            resObj.putInt(PhomFlag.PLAYER_FINISH, playerFinish);
        }
        resObj.putInt("show_type", showPhomType);
        ext.send(PhomCommand.DRAW_CARD, resObj, user);
        log(resObj);
    }

    public void sendDrawCardTurn(int gameTurn, int canU) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.DRAW_CARD_TURN, gameTurn);
        resObj.putInt(PhomFlag.CAN_U, canU);
        ext.send(PhomCommand.DRAW_CARD_TURN, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    public void showPhom(int havePhom, List<Integer> listPhom, int playerFinish,
            User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.HAVE_PHOM, havePhom);
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        resObj.putInt(PhomFlag.PLAYER_FINISH, playerFinish);
        ext.send(PhomCommand.SHOW_PHOM, resObj, user);
        log(resObj);
    }

    public void notifyPhom(int havePhom, List<Integer> listPhom, int playerFinish) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.HAVE_PHOM, havePhom);
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        resObj.putInt(PhomFlag.PLAYER_FINISH, playerFinish);
        ext.send(PhomCommand.NOTIFY_PHOM, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendMatchFinish(List<Integer> havePhom, List<Integer> playerRank, List<Long> moneyResult, List<Long> playerMoney, int tableHost) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(PhomFlag.HAVE_PHOM, havePhom);
        resObj.putLongArray(PhomFlag.MONEY_RESULT, moneyResult);
        resObj.putIntArray(PhomFlag.PLAYER_RANK, playerRank);
        resObj.putLongArray(PhomFlag.PLAYER_MONEY, playerMoney);
        resObj.putInt(PhomFlag.TABLE_HOST, tableHost);
        ext.send(PhomCommand.FINISH_MATCH, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendGameTurn(int gameTurn, int cardFight, int lastFight, int canEat) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.GAME_TURN, gameTurn);
        resObj.putInt(PhomFlag.CAN_DRAW_CARD, 1);
        resObj.putInt(PhomFlag.PLAYER_FIGHT, lastFight);
        resObj.putInt(PhomFlag.CARD_SEND, cardFight);
        resObj.putInt(PhomFlag.CAN_EAT, canEat);
        ext.send(PhomCommand.GAME_TURN, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendTransferCard(int srcPos, int desPos, int gameTurn) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.SOURCE_SEAT, srcPos);
        resObj.putInt(PhomFlag.DES_SEAT, desPos);
        resObj.putInt(PhomFlag.GAME_TURN, gameTurn);
        ext.send(PhomCommand.TRANSFER_CARD, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    public void sendEatCard(int cardFight, int playerFight, int gameTurn, int canU, List<User> userList) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.CARD_EAT, cardFight);
        resObj.putInt(PhomFlag.PLAYER_EAT, gameTurn);
        resObj.putInt(PhomFlag.PLAYER_FIGHT, playerFight);
        resObj.putInt(PhomFlag.CAN_U, canU);
        ext.send(PhomCommand.EAT_CARD, resObj, userList);
        log(resObj);
    }

    public void sendEatCard(int cardFight, int playerFight, int gameTurn, int canU, List<Integer> cardPhom,
            int showPhomType, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.CARD_EAT, cardFight);
        resObj.putInt(PhomFlag.PLAYER_EAT, gameTurn);
        resObj.putInt(PhomFlag.PLAYER_FIGHT, playerFight);
        resObj.putInt(PhomFlag.CAN_U, canU);
        if (!cardPhom.isEmpty()) {
            resObj.putIntArray(PhomFlag.CARD_PHOM, cardPhom);
            resObj.putInt(PhomFlag.HAVE_PHOM, 1);
        } else {
            resObj.putInt(PhomFlag.HAVE_PHOM, 0);
        }
        if (showPhomType != 0) {
            resObj.putInt(PhomFlag.PLAYER_FINISH, playerFight);
        }
        resObj.putInt("show_type", showPhomType);
        ext.send(PhomCommand.EAT_CARD, resObj, user);
        log(resObj);
    }

    public void sendPhomU(List<Integer> listPhom, int playerU, List<Long> moneyResult, List<Long> playerMoney, int tableHost) {
        delay();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
        }
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(PhomFlag.PHOM_U, listPhom);
        resObj.putInt(PhomFlag.PLAYER_U, playerU);
        resObj.putInt(PhomFlag.TABLE_HOST, tableHost);
        resObj.putLongArray(PhomFlag.MONEY_RESULT, moneyResult);
        resObj.putLongArray(PhomFlag.PLAYER_MONEY, playerMoney);
        ext.send(PhomCommand.PHOM_U, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    public void sendPhomU(int playerU, List<Long> moneyResult, List<Long> playerMoney, int tableHost) {
        delay();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
        }
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.TABLE_HOST, tableHost);
        resObj.putInt(PhomFlag.PLAYER_U, playerU);
        resObj.putLongArray(PhomFlag.MONEY_RESULT, moneyResult);
        resObj.putLongArray(PhomFlag.PLAYER_MONEY, playerMoney);
        ext.send(PhomCommand.PHOM_U, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendMoneyChange(long moneyChange, int playerWin, long playerWinMoney, int playerLost, long playerLostMoney) {
        delay();
       
        ISFSObject resObj = new SFSObject();
        resObj.putLong(PhomFlag.MONEY_CHANGE, moneyChange);
        resObj.putInt(PhomFlag.PLAYER_WIN, playerWin);
        resObj.putLong(PhomFlag.PLAYER_WIN_MONEY, playerWinMoney);
        resObj.putInt(PhomFlag.PLAYER_LOST, playerLost);
        resObj.putLong(PhomFlag.PLAYER_LOST_MONEY, playerLostMoney);
        ext.send(PhomCommand.MONEY_CHANGE, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendPlayerCard(PhomPlayer phomPlayer) {
//        delay();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
        }
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(PhomFlag.PLAYER_CARD, phomPlayer.getListCardIds());
        resObj.putInt(PhomFlag.PLAYER_POS, phomPlayer.getSeatPos());
        ext.send(PhomCommand.PLAYER_CARD, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    public void sendCardPhom(int seatPos, List<Integer> listPhom, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        resObj.putInt(PhomFlag.PLAYER_POS, seatPos);
        ext.send(PhomCommand.CHOOSE_PHOM, resObj, user);
        log(resObj);
    }

    public void sendDepositCard(int playerDeposit, LinkedList<Integer> listDepositCard, LinkedList<Integer> listDepositTarget) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(PhomFlag.DEPOSIT_CARD, listDepositCard);
        resObj.putIntArray(PhomFlag.DEPOSIT_TARGET, listDepositTarget);
        resObj.putInt(PhomFlag.PLAYER_DEPOSIT, playerDeposit);
        ext.send(PhomCommand.DEPOSIT_CARD, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    public void showPhomMore(int havePhom, List<Integer> listPhom, int seatPos,
            User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.HAVE_PHOM, havePhom);
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        resObj.putInt(PhomFlag.PLAYER_FINISH, seatPos);
        ext.send(PhomCommand.MORE_PHOM, resObj, user);
        log(resObj);
    }

    public void notifyPhomMore(int havePhom, List<Integer> listPhom, int playerFinish) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.HAVE_PHOM, havePhom);
        resObj.putIntArray(PhomFlag.CARD_PHOM, listPhom);
        resObj.putInt(PhomFlag.PLAYER_FINISH, playerFinish);
        ext.send(PhomCommand.NOTIFY_PHOM_MORE, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    public void notifyDeposit(int playerFinish,
            List<Integer> depositCard, List<Integer> depositTarget, User user) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.PLAYER_FINISH, playerFinish);
        if (!depositCard.isEmpty()) {
            resObj.putIntArray(PhomFlag.DEPOSIT_CARD, depositCard);
            resObj.putIntArray(PhomFlag.DEPOSIT_TARGET, depositTarget);
        }
        ext.send(PhomCommand.NOTIFY_DEPOSIT, resObj, user);
        log(resObj);
    }

    void sendUpdateTableHost(int newTableHost, int isPlay) {
        delay();
        ISFSObject resObj = new SFSObject();
        resObj.putInt(PhomFlag.TABLE_HOST, newTableHost);
        resObj.putInt(PhomFlag.IS_PLAY, isPlay);
        ext.send(PhomCommand.UPDATE_TABLE_HOST, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }
}
